package com.zzy.factory;
import java.util.HashMap;
import com.zzy.command.Command;
import com.zzy.command.Command1;
import com.zzy.command.Command2;
import com.zzy.command.Command3;
import com.zzy.command.CommandController;
public class CommandFactory implements CommandInterface{
	// 单例模式
    private static CommandFactory commandFactory = null;
    private CommandFactory() {
        commandMap.put(1, new Command1());
        commandMap.put(2, new Command2());
        commandMap.put(3, new Command3());
    }
    public static CommandFactory getCommandFactory() {
        if (commandFactory == null) {
            commandFactory = new CommandFactory();
        }
        return commandFactory;
    }
    CommandController commandController = CommandController.getCommandController();
    HashMap<Integer, Command> commandMap = new HashMap<Integer, Command>();
    private int flag = 0;
    public void setFlag(int flag) {
        this.flag = flag;
    }

	@Override
	public void build(String string) {
		// TODO Auto-generated method stub
		commandController.Action(commandMap.get(flag), string);
	}

}
